#include "comm.hpp"
#include <unistd.h>

using namespace std;

int main()
{
    key_t k = getKey();
    printf("0x%x\n",k);
    int shmid = getShm(k);
    printf("shmid: %d\n",shmid);
    
    
    char* start = (char*)attachShm(shmid);//进行链接
    printf("client关联成功 %p\n",start);

    //进行通信 /client进行写入
    //const char* message = "hello server 我是client,正在与你通信\n";
    const char* message = "I am process A\n";

    int cnt = 1;
    int n = 20;
    while(n--)
    {
        snprintf(start,MAX_SIZE,"%s [pid: %d][消息编号：%d]",message,getpid(),cnt++);
        sleep(1);
    }

    cout << "client去除关联" << endl;
    detachShm(start);//断开链接

    return 0;
}